* regressions_formal_employment_industry.do	JEP	04/29/15
* Does regressions for industry employment
* Monthly wages
* Exclude some industries
* Do regressions by city - industry
* Do not use city level employment as regressor, clearly endogenous.

*************************** Change log ********************************** 

/*
	
*/	

clear 
version 13.1

* Project info
cap project, doinfo
if _rc==198 {
	if c(os)=="Unix" loc master "/home/jperez/AA_Minimum_Wage" 
else if c(username)=="J16339" | c(username)=="A15858" loc master "B:\Col_Minimum_Wage" 
	else loc master "C:/Users/jorpp/Dropbox (Brown)/Col_Minimum_Wage"
 loc pr = 0
}
else {
	local master "`r(pdir)'"
	local doname "`r(dofile)'"  
 loc pr = 1
	* Project calls
	project, uses("`master'/Data/Source/ocupados_mw.dta")
	project, uses("`master'/Data/Source/empvars_informal_edom.dta")
	* Call programs
	project, relies_on("`master'/Code/Est/sample_choice.do")
	project, relies_on("`master'/Code/Est/build_mw_measures.do")
	project, relies_on("`master'/Code/Est/build_treatment.do")
	project, relies_on("`master'/Code/Est/export_ols.do")
	project, relies_on("`master'/Code/Est/confirmedrunols.do")	
}
*/

* di 84
* Call necessary programs. I do not call using project to carry the programs around. I do not put these in the ado/personal folder because they are specific to the project. They are not ado files.
do "`master'/Code/Est/sample_choice.do"
do "`master'/Code/Est/build_mw_measures_defl_nac.do"
do "`master'/Code/Est/build_treatment.do"
do "`master'/Code/Est/export_ols.do"
do "`master'/Code/Est/confirmedrunols.do"


use "`master'/Data/Source/ocupados_mw_alt.dta", clear

* Number of bootstraps
glo boot=500
*
* Choose sample
mysample e4sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) formal exind(13,29,42)
* Build mw measures
mw_measures e4sample , stub(e4)
* Build treatment
mytreatment, posts("tq(1999q1)") mw(bite_e_e4_ind) wage(salario_mensual_real_p)

* RIF regressions

* Create estimation results folder if it doesn't already exist
cap mkdir "`master'/Ster"
cap mkdir "`master'/Ster/e4_new_ebite_indcc_nce_defl_nac"

* For these I'm going to assume the clusters are the city - industry pairs. This assumes that there is not correlation within city across industries, only within those pairs. Could also run with the standard clustering by city, but that would mean that I'm not really increasing the sample size by running within industry.

* The number of clusters is  enough that I don't need the full CGM framework, can run just with cluster
egen city_ind=group(ccode cactividad_empresa)
if `pr'!=0 loc reg="register"
else loc reg ""

* Notice differences with rifs. Only one table for all specs, therefore only one name. First goes with replace, others with append.


* Keep one obs per city industry and merge with employment
drop if cactividad_empresa==.
bys ccode cactividad_empresa time: keep if _n==1
cap drop empind
merge 1:1 ccode cactividad time using "`master'/Data/Source/empvars_informal_edom.dta"
drop if cactividad==999
drop if inlist(cactividad_empresa,13,29,42)
drop if time==tq(1996q1)
assert _merge==3

* i_ind no se puede porque los inactivos no tienen industria

glo empvars "o_ind"

gen sample=1

foreach var in $empvars {

	loc name "`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_tq(1999q1)_bite_`var'_50_edom_indcc_nce"
	
	cap drop lempind
	gen lempind=log(`var')
	count
	* Panel A. Employment
	* confirmedrunols, `reg' y(lempind) controls() name(`name') ctitle(emp) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10A)  r(replace)  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) sample(sample) rerun
	* Panel B. Employment and Bartik Price Variable
	confirmedrunols, `reg' y(lempind) controls(bartikp1_ex_p) name(`name') ctitle(emp_bp) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_bp_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10B)  r(replace)  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) sample(sample) rerun
	* Panel C. Employment and Bartik Quantity Variable
	*confirmedrunols, `reg' y(lempind) controls(bartikq_ex) name(`name') ctitle(emp_bq) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_bq_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10C)  r(append)  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) sample(sample) rerun 
	* Panel D. Employment and City Trends
	*confirmedrunols, `reg' y(lempind) controls(i.ccode#c.trend ) name(`name') ctitle(sst_emp) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_sst_emp_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10D)  r(append)  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) sample(sample) rerun
	* Panel E. Employment, Bartik Price Variable and City Trends
	confirmedrunols, `reg' y(lempind) controls(i.ccode#c.trend bartikp1_ex_p) name(`name') ctitle(sst_emp_bp) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_sst_emp_bp_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10E)  r(append)  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) sample(sample) rerun
	* Panel F. Employment, Bartik Quantity Variable and City Trends
	*confirmedrunols, `reg' y(lempind) controls(i.ccode#c.trend bartikq_ex) name(`name') ctitle(sst_emp_bq) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_sst_emp_bq_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10F)  r(append)  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) sample(sample) rerun 
	* Panel G. Employment, Bartik Price Variable - Industry fe, city fe and interactions
	*confirmedrunols, `reg' y(lempind) controls(bartikp1_ex_p) name(`name') ctitle(emp_bp_ixc) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_bp_ixc_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10G)  r(append)  fe(i.ccode##i.cactividad_empresa i.time) cluster(ccode) sample(sample) rerun
	* Panel H. Employment, Bartik Quantity Variable and City - Industry fe, city fe and interactions
	*confirmedrunols, `reg' y(lempind) controls(bartikq_ex) name(`name') ctitle(emp_bq_ixc) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_bq_ixc_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10H)  r(append)  fe(i.ccode##i.cactividad_empresa i.time) cluster(ccode) sample(sample) rerun
	* Panel I - Employment, Bartik Price Variable - Industry fe, city fe and interactions - City Industry trends
	*confirmedrunols, `reg' y(lempind) controls(bartikp1_ex_p) name(`name') ctitle(ct_emp_bp_ixc) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_ct_emp_bp_ixc_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10I)  r(append)  fe(i.ccode##i.cactividad_empresa i.ccode#i.cactividad_empresa#c.trend i.time) cluster(ccode) sample(sample) rerun	
	* Panel J. Employment, Bartik Quantity Variable and City - Industry fe, city fe and interactions
	*confirmedrunols, `reg' y(lempind) controls(bartikq_ex) name(`name') ctitle(ct_emp_bq_ixc) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_ct_emp_bq_ixc_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10J)  r(append)  fe(i.ccode##i.cactividad_empresa i.ccode#i.cactividad_empresa#c.trend i.time) cluster(ccode) sample(sample) rerun
	* Panel L. Employment, Bartik Price Variable and City Trends and Industry Trends
	confirmedrunols, `reg' y(lempind) controls(bartikp1_ex_p i.ccode#c.trend i.cactividad_empresa#c.trend) name(`name') ctitle(itct) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_itct_bp_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10L) r(append)  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) sample(sample) rerun
	* Panel N. Employment, Bartik Price Variable and national employment by industry
	*confirmedrunols, `reg' y(lempind) controls(empind bartikp1_ex_p) name(`name') ctitle(ie_bp) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_ie_bp_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10N) r(append)  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) sample(sample)
	* Panel O. Employment, Bartik Price Variable and national employment by industry, city trends
	*confirmedrunols, `reg' y(lempind) controls(empind bartikp1_ex_p i.ccode#c.trend) name(`name') ctitle(iect_bp) ster(`master'/Ster/e4_new_ebite_indcc_nce_defl_nac/reg_iect_bp_tq(1999q1)_bite_`var'_50_edom_indcc_nce) rif(e10O) r(append)  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) sample(sample)
}	
